// ActionScript file
//import com.adobe.serialization.json.JSON;
import com.fm618.flex4.*;
import com.roguedevelopment.objecthandles.*;

import flash.events.Event;
import flash.events.MouseEvent;

import mx.collections.ArrayCollection;
import mx.containers.Canvas;
import mx.containers.VBox;
import mx.controls.Alert;
import mx.controls.Button;
import mx.controls.Image;
import mx.controls.Label;
import mx.controls.ProgressBar;
import mx.core.Container;
import mx.core.UIComponent;
import mx.events.DragEvent;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
import mx.events.ResizeEvent;
import mx.managers.DragManager;
import mx.graphics.codec.JPEGEncoder;
import mx.graphics.codec.PNGEncoder;
import mx.managers.PopUpManager;

[Bindable] private var ipaddress:String='www.kldiy.com';
//[Bindable] private var siteurl:String="http://" + ipaddress + "/xiu/";
[Bindable] private var siteurl:String="http://" + ipaddress + "/";

[Bindable] private var url_StagesRPC:String = siteurl+'stages.xml';
[Bindable] private var url_BordersRPC:String = siteurl+'borders.xml';
[Bindable] private var url_JewelryRPC:String = siteurl+'jewelry.xml';
[Bindable] private var url_TextRPC:String = siteurl+'texts.xml';
[Bindable] private var url_CalendarRPC:String = siteurl+'fm/getCalendar.php';
[Bindable] private var url_MyPhotoRPC:String = siteurl+'fm/getMyPhoto.php';


private var StageMenu:Array=new Array();
private var Stages:ArrayCollection=new ArrayCollection();
private var JewelryMenu:Array=new Array();
private var Jewelrys:ArrayCollection=new ArrayCollection();
private var TextMenu:Array=new Array();
private var Texts:ArrayCollection=new ArrayCollection();
private var CalendarMenu:Array=new Array();
private var Calendars:ArrayCollection=new ArrayCollection();
private var BorderMenu:Array=new Array();
private var Borders:ArrayCollection=new ArrayCollection();
private var MyUploadPhotos:ArrayCollection = new ArrayCollection(); // 上传的所有图片
private var MyMakedGoods:ArrayCollection = new ArrayCollection(); // 已经制作完成的图片

private var currentPhoto:String = new String(); //当前获得焦点的照片,  地址

private var processFlag:String = new String(); //当前处理标志
private var currentStage:String = new String(); //场景，台历
private var currentElement:ArrayCollection = new ArrayCollection(); // 操作区内所有的元素

//protected var objectHandles:ObjectHandles;

private var allobj:Array = new Array();

// 进度条
private var mask1:UIComponent = new UIComponent();
private var process1:ProgressBar = new ProgressBar();
private var process2:FmProgressBar = new FmProgressBar();

// 加载数据计数
private var countForLoad:Number = new Number();









[Bindable]
public var myar:ArrayCollection=new ArrayCollection([
		{name: "bw", urlx: SITEURL + "images/make/bw.png"}, 
		{name: "blur", urlx: SITEURL + "images/make/blur.png"}, 
		{name: "invert", urlx: SITEURL + "images/make/invert.png"}, 
		{name: "old", urlx: SITEURL + "images/make/old.png"}, 
		{name: "emboss", urlx: SITEURL + "images/make/emboss.png"}
		]);

[Bindable]public var myphoto:ArrayCollection = new ArrayCollection(); //用户上传的图片

[Bindable]public var myGoods:ArrayCollection = new ArrayCollection(); //用户完成的商品


/**
 * 初始化 
 * 
 */
public function init():void
{
	/*
	this.currentTabIndex = 0;
	this.countForLoad = 0;
	// 加载进度条
	mask1.id = 'st1';
	mask1.name = 'st1';
	mask1.width = this.width;
	mask1.height = this.height;
	mask1.x = 0;
	mask1.y = 0;
	//mask1.alpha = 0.9;
	var sp1:Sprite = new Sprite();
	//sp1.width = 100;
	//sp1.height = 100;
	sp1.graphics.beginFill(0xFFCC00,1);
	sp1.graphics.drawRect(0,0,mask1.width,mask1.height);
	//sp1.alpha = 0.9;
	mask1.addChild(sp1);
	
	process1.id = 'st1_pc1';
	process1.name = 'st1_pc1';
	process1.indeterminate = true;
	process1.width = 200;
	process1.labelPlacement = "bottom";
	process1.setStyle("barColor", 0xFFCC00);
	process1.setStyle("trackHeight", 20);
	process1.setStyle("textAlign", "center");
	process1.setStyle("textIndent", 50);
	process1.label = '数据加载……';
	//process1.x = mask1.width/2 -process1.width/2;
	//process1.y = mask1.height/2 - 15;
	process1.x = FlexGlobals.topLevelApplication.width/2 - process1.width/2;
	//process1.y = FlexGlobals.topLevelApplication.height/2 -15;
	//process1.x = Capabilities.screenResolutionX/2;
	process1.y = Capabilities.screenResolutionY/2-30;
	mask1.addChild(process1);
	addChild(mask1);
	setChildIndex(mask1, numChildren-1 );
	trace(Capabilities.screenResolutionY);
	// 进度条结束 ==*/
}
private function inited():void{
	this.setStyle("backgroundAlpha",0); //设置背景透明
	
	this.SendHttpService(this.url_MyMakedRPC, null,this.MakedRPCResult, 'Maked');
	
	//初始化素材数据
	//this.countForLoad++;
	//trace('stage @ '+this.countForLoad.toString());
	//this.process1.label='加载场景……';
	//StagesRPC.send();
	//this.SendHttpService(this.url_StagesRPC, null,this.StagesRPCResult, 'Stages');
	
	//this.countForLoad++;
	//trace('jewelry @ '+this.countForLoad.toString());
	//process1.label = '加载饰品……';
	//JewelryRPC.send();
	//this.SendHttpService(this.url_JewelryRPC, null,this.JewelryRPCResult, 'jewelrys');
	
	//this.countForLoad++;
	//trace('border @ '+this.countForLoad.toString());
	//process1.label = '加载边框……';
	//BordersRPC.send();
	//this.SendHttpService(this.url_BordersRPC, null,this.BorderRPCResult, 'Borders');
	
	//this.countForLoad++;
	//trace('text @ '+this.countForLoad.toString());
	//process1.label = '加载文字……';
	//TextRPC.send();
	//this.SendHttpService(this.url_TextRPC, null,this.TextRPCResult, 'Texts');
	/*
	this.countForLoad++;
	trace('Calendar @ '+this.countForLoad.toString());
	process1.label = '加载日历……'+this.countForLoad; 
	Alert.show(this.countForLoad.toString());
	//CalendarRPC.send();
	this.SendHttpService(this.url_CalendarRPC, null,this.CalendarRPCResult, 'Calendar');
	*/
	// 初始的左边栏
	brightness_value = 0;
	contrast_value = 0;
	saturation_value = 0;
	hue_value = 0;
	left_box.removeAllChildren();
	left_box.addChild(effectControls());
	
	// 初始化右边栏 我的照片
	MyPhotoRPC.send();
	
	
}
// 删除进度条
private function removeProcess1(event:Event):void{
	if(this.countForLoad <= 0){
		//this.removeChild( this.getChildByName('st1') );
	}
	trace(event.target.toString()+this.countForLoad);
}




/*
 * tabbar的点击事件，点击后改变主操作界面的内容
 */
protected function tabbar1_itemClickHandler(event:ItemClickEvent):void
{
	// TODO Auto-generated method stub
	//Alert.show(event.label);
	mainpaint.title=event.label;
	currentTabIndex = event.index;//
	switch (event.index)
	{
		case 0:
			if(this.temp_try_late){
				this.removeWeihu();
			}
			
			processFlag = 'effect'; // set process flag
			myar=new ArrayCollection([
				{name: "bw", urlx: SITEURL + "images/make/bw.png"}, 
				{name: "blur", urlx: SITEURL + "images/make/blur.png"}, 
				{name: "invert", urlx: SITEURL + "images/make/invert.png"}, 
				{name: "old", urlx: SITEURL + "images/make/old.png"}, 
				{name: "emboss", urlx: SITEURL + "images/make/emboss.png"}				 
				]);
			left_box.removeAllChildren();
			left_box.addChild(effectControls());
			
						
			break;
		case 1:
			this.weihu();
			break;
			processFlag = 'stage'; // set process flag
			// 设置场景素材
			myar=new ArrayCollection(Stages[0]);
			var vbox_s:VBox=new VBox();
			vbox_s.id='bvb';
			vbox_s.percentWidth=100;
			vbox_s.percentHeight=100;
			vbox_s.setStyle("horizontalCenter", 0);

			var contb:Number=new Number();
			contb=0;
			for each (var tem:Object in StageMenu)
			{
				var Sbtn:Button=new Button();
				Sbtn.label=tem.name;
				Sbtn.id=contb.toString();
				Sbtn.setStyle("horizontalCenter", 0);
				Sbtn.setStyle("horizontalAlign", "center");
				Sbtn.addEventListener(MouseEvent.CLICK, changeStages);
				Sbtn.percentWidth=100;
				vbox_s.addChild(Sbtn);
				contb++;
			}
			left_box.removeAllChildren();
			left_box.addChild(vbox_s);
			//trace();
			
			break;
		case 2:
			this.weihu();
			break;
			processFlag = 'border'; // set process flag
			//myar=Borders[0];
			myar=new ArrayCollection(Borders[0]);
			var vbox_b:VBox=new VBox();
			vbox_b.id='bvb';
			vbox_b.percentWidth=100;
			vbox_b.percentHeight=100;
			vbox_b.setStyle("horizontalCenter", 0);

			var contb1:Number=new Number();
			contb1=0;
			for each (var tem1:Object in BorderMenu)
			{
				var Bbtn:Button=new Button();
				Bbtn.label=tem1.name;
				Bbtn.id=contb1.toString();
				Bbtn.setStyle("horizontalCenter", 0);
				Bbtn.setStyle("horizontalAlign", "center");
				Bbtn.addEventListener(MouseEvent.CLICK, changeBorders);
				Bbtn.percentWidth=100;
				vbox_b.addChild(Bbtn);
				contb1++;
			}
			left_box.removeAllChildren();
			left_box.addChild(vbox_b);

			break;
		case 3:
			this.weihu();
			break;
			processFlag = 'jewelry'; // set process flag
			//myar=unitJewelry[0].info;
			myar=new ArrayCollection(Jewelrys[0]);
			var vbox_j:VBox=new VBox();
			vbox_j.id='bvb';
			vbox_j.percentWidth=100;
			vbox_j.percentHeight=100;
			vbox_j.setStyle("horizontalCenter", 0);

			var contb2:Number=new Number();
			contb2=0;
			for each (var tem2:Object in JewelryMenu)
			{
				var Jbtn:Button=new Button();
				Jbtn.label=tem2.name;
				Jbtn.id=contb2.toString();
				Jbtn.setStyle("horizontalCenter", 0);
				Jbtn.setStyle("horizontalAlign", "center");
				Jbtn.addEventListener(MouseEvent.CLICK, changeJewelrys);
				Jbtn.percentWidth=100;
				vbox_j.addChild(Jbtn);
				contb2++;
			}
			left_box.removeAllChildren();
			left_box.addChild(vbox_j);
			break;
		case 4:
			this.weihu();
			break;
			processFlag = 'texts'; // set process flag
			//myar=unitTexts[0].info;
			myar=new ArrayCollection(Texts[0]);
			var vbox_t:VBox=new VBox();
			vbox_t.id='bvb';
			vbox_t.percentWidth=100;
			vbox_t.percentHeight=100;
			vbox_t.setStyle("horizontalCenter", 0);

			var contb3:Number=new Number();
			contb3=0;
			for each (var tem3:Object in TextMenu)
			{
				var Tbtn:Button=new Button();
				Tbtn.label=tem3.name;
				Tbtn.id=contb3.toString();
				Tbtn.setStyle("horizontalCenter", 0);
				Tbtn.setStyle("horizontalAlign", "center");
				Tbtn.addEventListener(MouseEvent.CLICK, changeTexts);
				Tbtn.percentWidth=100;
				vbox_t.addChild(Tbtn);
				contb3++;
			}
			left_box.removeAllChildren();
			left_box.addChild(vbox_t);
			break;
		/*case 5:
			processFlag = 'calendar'; // set process flag
			//myar=unitCalendar[0].info;
			myar=new ArrayCollection(Calendars[0]);
			var vbox_c:VBox=new VBox();
			vbox_c.id='cavb';
			vbox_c.percentWidth=100;
			vbox_c.percentHeight=100;
			vbox_c.setStyle("horizontalCenter", 0);

			var contb4:Number=new Number();
			contb4=0;
			for each (var tem4:Object in CalendarMenu)
			{
				var Cbtn:Button=new Button();
				Cbtn.label=tem4.name;
				Cbtn.id=contb4.toString();
				Cbtn.setStyle("horizontalCenter", 0);
				Cbtn.setStyle("horizontalAlign", "center");
				Cbtn.addEventListener(MouseEvent.CLICK, changeCalendars);
				Cbtn.percentWidth=100;
				vbox_c.addChild(Cbtn);
				contb4++;
			}
			left_box.removeAllChildren();
			left_box.addChild(vbox_c);
			break;*/
		default:
			break;

	}
}

/*
 * 文字处理的左边栏
 */
private function textsLeft():void{

}

//特效设置,将数据存到变量里。
private function sendEffect(tar:Object):void{
	var val:Number = new Number();
	//Alert.show(tar.toString());
	switch(tar.toString()){
		case 'hs_hue':
			val = hue_value;
			break;
		case 'hs_sat':
			val = saturation_value;
			break;
		case 'hs_con':
			val = contrast_value;
			break;
		case 'hs_bri':
			val = brightness_value;
			break;
		
		default :
			val = -1;
			break;
	}
		
	 
}
// 回调函数 for saveEffect
private function testCompleteHandler(event:Event):void{
	var l:URLLoader = URLLoader(event.target);  
    //var o:Object = URLUtil.stringToObject(String(l.data)); //使用URLUtil对将数据进行反序列化以方便使用  
	trace(l.data);
	//testlab.text = l.data;
}
// 送至服务器生成图片
private function saveEffect(event:MouseEvent):void{
	var v:URLVariables = new URLVariables();
	v.brightness = 0; 
	v.contrast = 0;
	v.saturation = 0;
	v.hue = 0;
	v.currentphoto = currentPhoto;
	if(currentPhoto == ''){
		Alert.show('file is null');
	}else{
    	var r:URLRequest = new URLRequest();
    	r.url = siteurl +"process.php";  
    	r.method = URLRequestMethod.GET;  
    	r.data = v;
    	var l:URLLoader = new URLLoader();  
    	l.load(r);  
    	l.addEventListener(Event.COMPLETE,testCompleteHandler);//注册请求完成后 响应获取数据事件方法  
 	}
}






/*
 * 左边素材分类的点击事件
 */
private function changeBorders(event:MouseEvent):void
{
	myar=new ArrayCollection(Borders[event.target.id]);
}

private function changeStages(event:MouseEvent):void
{
	myar=new ArrayCollection(Stages[event.target.id]);
}

private function changeJewelrys(event:MouseEvent):void
{
	myar=new ArrayCollection(Jewelrys[event.target.id]);
}

private function changeTexts(event:MouseEvent):void
{
	myar=new ArrayCollection(Texts[event.target.id]);
}

private function changeCalendars(event:MouseEvent):void
{
	myar=new ArrayCollection(Calendars[event.target.id]);
}

private function leftclick(event:ListEvent):void{
	switch(currentTabIndex){
		case 0 :
			trace(event.itemRenderer.data);
			trace(mainpaint.width);
			doEffect(event.itemRenderer.data.name);
			break;
		case 1 : //场景
			addStage(event.itemRenderer.data.urlx, event.itemRenderer.data.name);
			break;
		case 2 : //边框
			break;
		case 3 : //饰品
			addJewelry(event.itemRenderer.data.urlx, event.itemRenderer.data.name);
			break;
		case 4 : //文字
			break;
		case 5 : //日历
			addStage(event.itemRenderer.data.urlx, event.itemRenderer.data.name);
			break;
		default :
			break;
	}
}

/**
 * 场景，日历 性质相同，主体不动，照片调整。
 * @param String url_x 图片地址
 * @param String name_x 名称
 * @return NULL
 */
private function addStage(url_x:String, name_x:String):void{
	var img:Image = new Image();
	var stage1:MyStage = new MyStage();
	img.source = url_x;
	stage1.source = url_x;
	stage1.type = 'stage'; //设置元件的类型。
	stage1.zindex = 0;
	stage1.id = 'stage'+name_x;
	stage1.name = stage1.id;
	stage1.addEventListener(ResizeEvent.RESIZE, recom)
	stage1.addEventListener(MouseEvent.MOUSE_OVER, m_over);
	
	//img.id = 'stage_'+name_x;
	//img.name = img.id;
	//img.addEventListener(ResizeEvent.RESIZE, recom); //重新调整图片大小
	//img.addEventListener(MouseEvent.MOUSE_OVER, m_over); //鼠标经过事件
	if(currentStage!=''){
		mainpaint.removeChild(mainpaint.getChildByName(currentStage));
	}
	mainpaint.addChild(stage1);
	mainpaint.setChildIndex(stage1, mainpaint.numChildren -1);
	currentStage = stage1.source.toString();
	trace(currentStage);
	//mainpaint.addChild(img);
	//mainpaint.setChildIndex(img, mainpaint.numChildren-1);
	//trace(img.width);
	//currentStage = img.source.toString();
}
// addStage回调
/**
 * addStage回调函数，重新调整图片大小，宽度为90%,高度为90%，y为88，x为父容器宽度/2-this.width/2-15。 
 * @param ResizeEvent event
 * 
 */
private function recom(event:ResizeEvent):void{
	var img:Image = event.target as Image;
	if(img.width>600){
		img.percentWidth = 90;
		img.percentHeight = 90;
	}
	img.x = mainpaint.width/2 - img.width/2 -15;
	img.y = 88;
	trace(img.height);
}

private function m_over(event:MouseEvent):void{
	event.currentTarget.parent.setChildIndex(event.currentTarget, 0);
}


/*
 * 我的照片的事件，拖放照片到做图区
 */
private function selectPhoto(event:ListEvent):void{
	if(currentElement.length<5){
	//trace(event.itemRenderer.data.urlx);
	var instance:Image=new Image();
	instance.source = event.itemRenderer.data.urlx;
	instance.id = event.itemRenderer.data.name;
	instance.addEventListener(MouseEvent.MOUSE_DOWN, startMove);
	instance.addEventListener(MouseEvent.MOUSE_UP, stopMove);
	//mainpaint.addEventListener(DragEvent.DRAG_ENTER, paintDragEnter);
	//mainpaint.addEventListener(DragEvent.DRAG_DROP, paintDragDrop);
	
	var oh:ObjectHandles = new ObjectHandles();
	oh.height = 100;
	oh.width = 100;
	instance.percentHeight = 100;
	instance.percentWidth = 100;
	instance.maintainAspectRatio = false
	oh.addChild(instance);
	oh.allowRotate = true;
	oh.addEventListener(ResizeEvent.RESIZE, 
						function(event:ResizeEvent):void{
							//event.currentTarget.getChildren()[0].height = event.currentTarget.height;
						});
	oh.y = 88;
	oh.id = 'oh_'+instance.id+currentElement.length;
	mainpaint.addChild(oh);
	mainpaint.setChildIndex(oh, 0);
	currentPhoto = instance.source.toString();
	currentElement.addItem({source:instance.source.toString(), id:oh.id, xflag:'photo'});
	}else{
		Alert.show('添加的照片太多了！','注意');
	}
}
// startMove
private function startMove(event:MouseEvent):void{
	event.currentTarget.startDrag();
	//var dragInitiator:UIComponent=UIComponent(event.currentTarget);
	//var ds:DragSource = new DragSource();
    //ds.addData(dragInitiator, "myRule");
    //DragManager.doDrag(dragInitiator, ds, event);
}
private function stopMove(event:MouseEvent):void{
	event.currentTarget.stopDrop();
}
private function paintDragEnter(event:DragEvent):void{
	if (event.dragSource.hasFormat("myRule ")){
       DragManager.acceptDragDrop(UIComponent(event.currentTarget));
    }	
}
private function paintDragDrop(event:DragEvent):void{
	var dragObject:UIComponent=UIComponent(event.dragInitiator);
           dragObject.x = Container(event.currentTarget).mouseX;

           dragObject.y =Container(event.currentTarget).mouseY;
           if(dragObject.parent!=event.currentTarget){
             Container(event.currentTarget).addChild(dragObject);
           }
           //trace(dragObject.parent);
}
			
private function paintComplete(event:Event):void{
	event.currentTarget.childItem
}			
/**
 * 显示维护信息
 */
public function weihu():void{
	if(this.temp_try_late){
		this.removeWeihu();
		trace('message was show');
	}
	var tmp1:Canvas = new Canvas();
	tmp1.percentWidth = 100;
	tmp1.percentHeight = 100;
	tmp1.setStyle("backgroundColor", '#CCCCCC');
	tmp1.alpha = 1;
	tmp1.id = 'mmmm';
	tmp1.name = 'mmmm';
	var ll:Label = new Label();
	ll.text = '系统维护中，请稍后再试。';
	ll.x = 400;
	ll.y = 200;
	tmp1.addChild(ll);
	mmm.addChild(tmp1);
	this.temp_try_late = true;
}
/**
 * 删除维护信息
 */
public function removeWeihu():void{
	trace(mmm.getChildByName('mmmm'));
	mmm.removeChild(mmm.getChildByName('mmmm'));
	this.temp_try_late = false;
}

private function myPDClick(e:ListEvent):void{
	trace(e.itemRenderer.data);
	trace(this.current_opt);
	
	switch(currentTabIndex){
		case 0:
			// 特效事件，对照片处理。
			onEffect(e.itemRenderer.data);
			break;
		
		default :
			trace('myPDClick is default');
			break;
	}
	
}

// 完成设计
private function finishPic():void{
	if(currentPhoto==''){
		Alert.show('您还未选择照片。','注意');
		return;
	}
	
	var v:URLVariables = new URLVariables();
	v.process = processFlag;
	v.currentPhoto = currentPhoto; 
	v.currentStage = currentStage;
	//v.elements = JSON.encode(currentElement);
	
	for(var i:uint=0;i<currentElement.length;i++){
		//trace("id is "+currentElement.getItemAt(i).id);
		//trace("source is "+currentElement.getItemAt(i).source);
		//trace("xflag is " + currentElement.getItemAt(i).xflag);
		//trace(currentElement.getItemAt(i).x);
	
	}
	for(var ii:uint=0; ii<mainpaint.numChildren; ii++){
		if(mainpaint.getChildAt(ii) is ObjectHandles){
			trace('scale X is '+mainpaint.getChildAt(ii).scaleX);
			trace('scale Y is '+mainpaint.getChildAt(ii).scaleY);
			trace('X is '+mainpaint.getChildAt(ii).x);
			trace('Y is '+mainpaint.getChildAt(ii).y);
			trace('Rotation is '+mainpaint.getChildAt(ii).rotation);
		}
	}
	trace('currentPhoto', currentPhoto.length);
	trace('= finishpic =');
	/*
	if(currentPhoto == ''){
		Alert.show('file is null');
	}else{
    	var r:URLRequest = new URLRequest();
    	r.url = "http://localhost/process.php";  
    	r.method = URLRequestMethod.GET;  
    	r.data = v;
    	var l:URLLoader = new URLLoader();  
    	l.load(r);  
    	l.addEventListener(Event.COMPLETE,testCompleteHandler);//注册请求完成后 响应获取数据事件方法  
 	}
 	*/
}
/**
 * 保存图片
 */
private function onSaveJPG():void
{
	var paintGrab:BitmapData = new BitmapData(effect_img.width,effect_img.height);
	paintGrab.draw(effect_img);
	
	var myEncoder:JPEGEncoder = new JPEGEncoder(100);
	var byteArray:ByteArray = myEncoder.encode(paintGrab);
	
	var header:URLRequestHeader = new URLRequestHeader("Content-type", "applicaton/octet-stream");
	var tmpurl:String = new String();
	tmpurl = "savejpg.php?w="+effect_img.width+'&h='+effect_img.height;
	var saveJPG:URLRequest = new URLRequest(tmpurl);
	saveJPG.requestHeaders.push(header);
	saveJPG.method = URLRequestMethod.POST;
	saveJPG.data = byteArray;
	//navigateToURL(saveJPG, "_blank");
	var l:URLLoader = new URLLoader();  
	l.load(saveJPG);  
	l.addEventListener(Event.COMPLETE,FinishRequest);
}
/**
 * onSaveJPG的回调
 */
private function FinishRequest(e:Event):void{
	var l:URLLoader = URLLoader(e.target);  
	//var o:Object = URLUtil.stringToObject(String(l.data)); //使用URLUtil对将数据进行反序列化以方便使用  
	trace(l.data);
	if(l.data == 'OK'){
		Alert.show('保存成功！');
		mymaked.removeAll();
		this.SendHttpService(this.url_MyMakedRPC, null,this.MakedRPCResult, 'Maked');
	}else{
		Alert.show('系统忙，请稍后再试！');
	}
}


/**
 * 完成设计
 */
private function onFinish():void{
	if(currentPhoto==''){
		Alert.show('尚未选择照片。','注意');
		return;
	}
	switch(currentTabIndex){
		case 0 :
			trace('effect finish');
			onSaveJPG();
			break;
		case 1 : //场景
			
			break;
		case 2 : //边框
			break;
		case 3 : //饰品
			
			break;
		case 4 : //文字
			break;
		case 5 : //日历
			
			break;
		default :
			break;
	}
}

/**
 * 上传照片，弹出式对话框。
 */
private function ShowUploadMyPhotoDialog(e:MouseEvent):void{
	// 这里第三个参数 true 表示: 弹出myPanel窗口后, 是否可以对父级操作, 值为true时, 就会产生背景模糊的效果, 并不能对父级的东西进行操作
	var pop1:UploadPhotoM = UploadPhotoM(PopUpManager.createPopUp(this, UploadPhotoM, true)); 
	pop1.mapp = this;
	pop1.cbFunc = this.popFunction;
}
/**
 * 上传照片，弹出式对话框。
 */
private function ShowUploadMyPhotoDialog1(e:MouseEvent, tHandle:Object):void{
	// 这里第三个参数 true 表示: 弹出myPanel窗口后, 是否可以对父级操作, 值为true时, 就会产生背景模糊的效果, 并不能对父级的东西进行操作
	var pop1:UploadPhotoM = UploadPhotoM(PopUpManager.createPopUp(this, UploadPhotoM, true)); 
	pop1.mapp = tHandle;
	pop1.cbFunc = this.popFunction;
}
/**
 * 上传照片的回调函数
 */
private function popFunction(value:Object):void{
	/*this.HTTPSeMyPhoto = false;
	ss = new SplashScreen();
	ss.percentWidth = 100;
	ss.percentHeight = 100;
	ss.label = 'Splash Screen';
	ss.setStyle('backgroundColor', '#ffff66');
	ss.setStyle('horizontalCenter', '0');
	ss.setStyle('verticalCenter', '0');
	ss.setTrackHeight(20);
	ss.alpha = 0.0;
	addChild(ss);
	ss.setLabel('读取照片');*/
	MyUploadPhotos.removeAll();
	this.SendHttpService(this.URLMyPhotoRPC, null,this.getMyPhotoRPCResult, '读取照片');
	/*trace(myphotoCanvas.getChildByName('temp1'));
	if(myphotoCanvas.getChildByName('temp1')!=null){
		myphotoCanvas.removeChild( myphotoCanvas.getChildByName('temp1'));//temp1是初始化时创建的提示未上传照片的canvas
	}*/
}

